/**
 * @author: dn-jinmin/dn-jinmin
 * @doc:
 */

package main

import "fmt"

// 打卡信息状态接口
type ClockState interface {
	Handle() string
}

// 正常状态
type NormalState struct{}

func (n *NormalState) Handle() string {
	return "正常"
}

// 迟到状态
type LateState struct{}

func (l *LateState) Handle() string {
	return "迟到"
}

// 早退状态
type EarlyState struct{}

func (e *EarlyState) Handle() string {
	return "早退"
}

// 旷工状态
type AbsentState struct{}

func (a *AbsentState) Handle() string {
	return "旷工"
}

// 请假状态
type LeaveState struct{}

func (l *LeaveState) Handle() string {
	return "请假"
}

// 打卡信息类
type ClockInfo struct {
	state ClockState
}

// 简单工厂类
type ClockFactory struct{}

func (f *ClockFactory) GetClockState(cartType string) ClockState {
	switch cartType {
	case "normal":
		return &NormalState{}
	case "late":
		return &LateState{}
	case "early":
		return &EarlyState{}
	case "absent":
		return &AbsentState{}
	case "leave":
		return &LeaveState{}
	default:
		return nil
	}
}

func (c *ClockInfo) SetState(cartType string) {
	factory := &ClockFactory{}
	state := factory.GetClockState(cartType)
	c.state = state
}

func (c *ClockInfo) GetState() string {
	if c.state == nil {
		return "未打卡"
	}
	return c.state.Handle()
}

func main() {
	clock := &ClockInfo{}
	fmt.Println(clock.GetState()) // 未打卡

	clock.SetState("normal")
	fmt.Println(clock.GetState()) // 正常

	clock.SetState("late")
	fmt.Println(clock.GetState()) // 迟到

	clock.SetState("early")
	fmt.Println(clock.GetState()) // 早退

	clock.SetState("absent")
	fmt.Println(clock.GetState()) // 旷工

	clock.SetState("leave")
	fmt.Println(clock.GetState()) // 请假
}
